package com.phicomm.cloud.controller;

import com.phicomm.cloud.senseTime.ImageVerificationStateless;
import com.phicomm.cloud.util.ImageConvert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/web")
public class WebController {
	
	private static final Logger logger =  LoggerFactory.getLogger(WebController.class);
	private final String filepath="/usr/local/jar/images/";
	private String filepath1=filepath+"1.jpg";
	private String filepath2=filepath+"2.jpg";
	
	@RequestMapping("index")
	public String index(ModelMap map){
		return "index";
	}

	@ResponseBody
	@RequestMapping("verify")
	public String verify(ModelMap map){
		try {
			return new ImageVerificationStateless().httpClientPost(filepath1,filepath2);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@ResponseBody
	@RequestMapping("generate")
	public List<String> generate(ModelMap map, @RequestParam String sel1,@RequestParam String sel2){
		filepath1=filepath+sel1+".jpg";
		filepath2=filepath+sel2+".jpg";
		List<String> list = new ArrayList<>();
		list.add(new ImageConvert().getImageStr(filepath1));
		list.add(new ImageConvert().getImageStr(filepath2));
		return list;
	}

}
